def Prost(n):
        for d in range(2, n):
                if n % d == 0:
                        return False
        return True


n = int(input())
if n >= 1000 and n < 10000:
        n1 = n % 1000
        n2 = n // 10
        n3 = n // 100
        n4 = n % 100
        n5 = n % 1000 // 10
        n6 = n // 1000
        n7 = n % 1000 // 10
        n8 = n // 10 % 10
        n9 = n % 10
        m = 0
        if Prost(n) and n > m:
                m = n
        if Prost(n1) and n1 > m:
                m = n1
        if Prost(n2) and n2 > m:
                m = n2
        if Prost(n3) and n3 > m:
                m = n3
        if Prost(n4) and n4 > m:
                m = n4
        if Prost(n5) and n5 > m:
                m = n5
        if Prost(n6) and n6 > m:
                m = n6
        if Prost(n7) and n7 > m:
                m = n7
        if Prost(n8) and n8 > m:
                m = n8
        if Prost(n9) and n9 > m:
                m = n9
        print(m)           
else:
        print("0")
                
